package com.zzedu.integration.oss.tencent.config;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.http.HttpProtocol;
import com.qcloud.cos.region.Region;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(TencentProp.class)
public class TencentConfig {

    private static final Logger log = LoggerFactory.getLogger(TencentConfig.class);

    @Autowired
    private TencentProp tencentProp;

    /**
     * 获取 MinioClient
     */
    @Bean
    public COSClient cosClient() {
        COSCredentials cred = new BasicCOSCredentials(tencentProp.getSecretId(), tencentProp.getSecretKey());
        ClientConfig clientConfig = new ClientConfig(new Region(tencentProp.getRegion()));
        clientConfig.setHttpProtocol(HttpProtocol.https);
        return new COSClient(cred, clientConfig);
    }
}